import 'package:flutter/material.dart';
import './myFonts.dart';

//ListView列表组件
void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('ListView动态列表组件'),
          backgroundColor: Colors.pink[50],
        ),
        body: MyHomePage(),
      ),
    );
  }
}

class MyHomePage extends StatelessWidget {
  const MyHomePage({super.key});

//生成动态列表
  List<Widget> _initListDate(){
    List<Widget> list = [];
    for(var i = 0; i < 20; i++){
      list.add(
        ListTile(
          title: Text('列表项$i'),
        )
      );
    }
    return list;
  }

  @override
  Widget build(BuildContext context) {
    return ListView(
      children: _initListDate(),//
    );
  }
}
